package com.bpms.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.service.devimonitor.Atmpdevicestatusserviceimpl;
import com.service.util.StringUtil;
import com.zk.atm.forms.AtmpDeviceStatusForm;

/**
 * @author zengqun
 * @remark 获取客户端：所有设备的状态，通过此servlet来读写
 * @date 2012-9-24
 * @version 1.0
 */
public class DeviceStatusServlet extends BaseServlet {

	private Atmpdevicestatusserviceimpl atmpDeviceStatusServcie;
	
	public Atmpdevicestatusserviceimpl getIAtmpDeviceStatusService(){
		if(this.atmpDeviceStatusServcie==null){
			this.atmpDeviceStatusServcie=new Atmpdevicestatusserviceimpl();
		}
		return this.atmpDeviceStatusServcie;
	}
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doWriteStatus(request,response);
		
	}

	private void doWriteStatus(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException  {
		String devstatus=StringUtil.getPropertyValue(request.getParameter("devstatus"));
		if(devstatus.equals("")){
			response.getWriter().write("N");
			return;
		}
		AtmpDeviceStatusForm statusForm=new AtmpDeviceStatusForm();
		statusForm.setDevstatus(devstatus);
		try {
			boolean is_success=this.getIAtmpDeviceStatusService().saveDevcieStatus(statusForm);
		    String message="Y";
		    message=new Date().toLocaleString();
		    if(is_success==false){
		    	message="N:"+message;
		    }
		    response.getWriter().write(message);
		    return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
